package com.elcl.util;

import android.content.Context;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.Log;

/**
 * @author LCL
 * 2014-12-3
 * 设备的相关内容
 */
public class DeviceUtils {

	/**
	 * 获取手机的型号
	 */
	public static String getMPhoneModle() {
		Log.i("MODEL", Build.MODEL + "VERSION" + Build.VERSION.RELEASE
				+ "MANUFACTURER" + Build.MANUFACTURER + ""
				+ "Build.VERSION.CODENAME" + Build.VERSION.CODENAME
				+ " Build.VERSION.SDK_INT" + Build.VERSION.SDK_INT
				+ " Build.DEVICE" + Build.DEVICE + " Build.BRAND" + Build.BRAND
				+ "Build.PRODUCT" + Build.PRODUCT);
		return Build.MODEL;
	}
	
	/**
	 * 获取手机的版本号(获取的是2.3.5类似的格式)
	 */
	public static String getMPhoneSDKVersion(){
		return Build.VERSION.RELEASE;
	}
	
	/**
	 * 获取手机的型号(例如，MI2)
	 */
	public static String getMPhoneType(){
		return Build.MODEL;
	}
	
	/**
	 * 获取手机的版本号(9-18类似的数据)
	 */
	public static int getMPhoneSDKNumber(){
		return Build.VERSION.SDK_INT;
	}
	
	/**
	 * 获取手机的厂商名称
	 */
	public static String getMPhoneManufacturer(){
		return Build.MANUFACTURER;
	}
	
	/**
	 * 获取手机的地址
	 */
	public static void getMPhoneLocation(Context ctx){
		TelephonyManager telephonyManager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
		telephonyManager.getCellLocation();
	}
	
	/**
	 * 获取手机唯一标示IMEI
	 * 一个没有量产的手机（水货）它可能有无效的IMEI
	 */
	public static String getMPhoneIMEI(Context ctx){
		TelephonyManager TelephonyMgr = (TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE); 
		String szImei = TelephonyMgr.getDeviceId(); 
		return szImei;
	}
	
	/**
	 * 获取手机号码
	 *  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
	 *  并不是所有的手机都能获取到手机号，eg：移动的神舟行和联通可以获得，动感地带不可以，其他未知
	 */
	public static String getMPhoneNumber(Context ctx){
		TelephonyManager telephonyManager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
		String tel = telephonyManager.getLine1Number();
		return tel;
	}
}
